Dictionaries
Represents a (mutable) set $S$ of elements with keys
Operations
insert(D, x)
- add an element
x
- add an element
remove(D, x)
- remove
x
from the set
- remove
search(D, x)
- check if an element with key
x
is in the set, and return it if found
- check if an element with key
Binary Search Trees
BST Property
For each node, keys in left subtree <= root key <= keys in right subtree.
Traversals
- in-order:
- traverse left subtree in-order
- visit root
- traverse right subtree in-order
- pre-order:
- visit root
- traverse left subtree pre-order
- traverse right subtree pre-order
- post-order:
- traverse left subtree post-order
- traverse right subtree post-order
- visit root
Rotations
…
Set Operations on BSTs
search(D, x)
def search(D, x):
if (x == D.root):
return D.root
elif (x < D.root):
return search(D.left_child, x)
else:
return search(D.right_child, x)